package com.javastudy.liuhouse.lambda.stream;

import java.util.function.LongSupplier;

public class FibSupplier implements LongSupplier {
    //前一个斐波那契数
    private long previous = 0;
    //当前斐波那契数
    private long current = 1;

    @Override
    public long getAsLong() {
        //保存当前值
        long next = current;
        //计算下一个斐波那契数
        current = previous + current;
        //更新前一个值
        previous = next;
        //返回当前值
        return next;
    }
}
